﻿using System.Text;
using System.Web.UI;
using _5E.Utils.UserControlHelper;
using _5E.Utils.WebHelper;

namespace Pool.WebSite.Service.Adapter
{
    class UserControlAdapter
    {
        private const string VIRTUAL_PATH = "~/uc/{0}UI.ascx";

        [Ajax]
        public string GetHtml(string module)
        {
            ViewManager<UserControl> view = new ViewManager<UserControl>();
            string path = string.Format(VIRTUAL_PATH, module);
            UserControl userControl = view.LoadViewControl(path);
            StringBuilder html = new StringBuilder(view.RenderView(userControl));
            html.AppendFormat(@"
<script type=""text/javascript"">
    oo('ajax').prop('module', '{0}');
    oo('{0}');
</script>", module);
            return html.ToString();
        }
    }
}
